package cn.group.service.impl;

import cn.group.dao.CourseDao;
import cn.group.domain.Course;
import cn.group.service.CourseService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {
    private CourseDao courseDao;

    @Autowired
    public void setCourseDao(CourseDao courseDao) {
        this.courseDao = courseDao;
    }


    @Override
    public List<Course> queryAllCourse() {
        return courseDao.queryAllCourse();
    }

    @Override
    public PageInfo<Course> getCourseByPage(Integer currentPage, Integer pageSize) {
        //拦截mybatis后续的查询
        PageHelper.startPage(currentPage, pageSize);
        List<Course> courseList=courseDao.queryAllCourse();
        System.out.println(courseList.size());
        PageInfo<Course> pageInfo=new PageInfo<>(courseList);
        return pageInfo;
    }

    @Override
    public Course queryCourseById(Integer id) {
        Course course=courseDao.queryCourseById(id);
        System.out.println(course);
        return course;

    }

    @Override
    public boolean modifyOne(Course course) {
        boolean result=courseDao.modifyOne(course);
        return result;
    }

    @Override
    public boolean insertOneCourse(Course course) {
        boolean result=courseDao.insertOneCourse(course);
        return result;
    }

    @Override
    public Boolean deleteOne(Course course) {
        Boolean result=courseDao.deleteOne(course);
        return result;
    }
}
